/**
 * @file bsp_linklist.h
 * @author liufeng (liufeng@injoinic.com)
 * @brief 用于WT588F02B的邻接表数据结构
 * @version 0.1
 * @date 2024-12-13
 *
 * @copyright Copyright (c) 2024  injoinic
 *
 */

#ifndef __BSP_LINKLIST_H__
#define __BSP_LINKLIST_H__

#include "stdbool.h"
#include "stdint.h"

/* 语音的最大优先级 */
#define WT588F_MAX_PRIORITY (15)

/* 语音结点定义 */
typedef struct voice_node_tag list_voice_node;
struct voice_node_tag
{
    uint8_t volume;            // 音量
    uint8_t priority;          // 优先级
    uint8_t voice_address;     // 语音地址

    list_voice_node* previous; // previous指针
    list_voice_node* next;     // next指针
};

/* 链表handler */
typedef struct list_handler_tag list_handler;
struct list_handler_tag
{
    uint8_t amount_of_node[WT588F_MAX_PRIORITY];                // 链表结点数量
    list_voice_node voice_list[WT588F_MAX_PRIORITY];            // 链表头结点数组
    uint8_t current_priority;                                   // 当前语音的优先级
    uint8_t highest_priority;                                   // 最高优先级

    uint8_t (*pf_add_node)(list_handler*, list_voice_node*);    // 增加一个语音结点
    uint8_t (*pf_delete_node)(list_handler*, list_voice_node*); // 删除一个语音节点
    uint8_t (*pf_sort)(list_handler*, uint8_t); // 同等优先级的结点，按语音地址升序排列
    list_voice_node* (*pf_first_node)(list_handler*); // 取最高优先级链表首结点地址
    bool (*pf_is_empty)(list_handler*);               // 判断链表handler是否为空
};

/* 链表handlr构造函数 */
extern uint8_t list_handler_construct(list_handler*);

#endif /* __BSP_LINKLIST_H__ */
